# Maintainer: Jonas Witschel <diabonas@archlinux.org>
pkgname=('libolm' 'python-olm')
pkgver=3.2.15
_tag=c2ccf54de20b2563331e273f113b2b51c59be619 # git rev-parse "$pkgver"
pkgrel=1
pkgdesc='Implementation of the Olm and Megolm cryptographic ratchets'
arch=('loong64' 'x86_64')
url='https://gitlab.matrix.org/matrix-org/olm'
license=('APACHE')
makedepends=('git' 'cmake' 'python' 'python-build' 'python-cffi' 'python-future'
             'python-installer' 'python-setuptools' 'python-wheel')
checkdepends=('python-aspectlib' 'python-pytest' 'python-pytest-benchmark')
source=("git+$url.git?signed#tag=$_tag")
sha512sums=('SKIP')
# PGP key can be obtained from https://packages.matrix.org/npm/olm/signing_key.asc
validpgpkeys=('56CF24AEE5F4513280CC594BF75FDC22C1DE8453') # Matrix.org olm <olm@matrix.org>

pkgver() {
	cd olm
	git describe | sed 's/\([^-]*-\)g/r\1/;s/-/./g'
}

build() {
	cd olm
	cmake -B build -DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_PREFIX=/usr
	cmake --build build

	cd python
	python -m build --wheel --no-isolation
}

check() {
	cd olm/build/tests
	ctest

	cd ../../python
	PYTHONPATH="$(find build -name 'lib.*' -type d -print)" LD_LIBRARY_PATH=../build pytest
}

package_libolm() {
	depends=('gcc-libs')
	provides=('libolm.so')

	cd olm/build
	make DESTDIR="$pkgdir" install
}

package_python-olm() {
	pkgdesc='Python bindings for Olm'
	depends=('libolm' 'python' 'python-cffi' 'python-future' 'libolm.so')

	cd olm/python
	python -m installer --destdir="$pkgdir" dist/*.whl
}
